package com.justgame.project.service.art.query;

import java.util.List;
import java.util.ArrayList;
import java.util.Optional;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.justgame.project.cloud.common.query.Column;
import com.justgame.project.cloud.common.query.BaseSelectBuilder;
import com.justgame.project.cloud.common.query.AbstractQueryWrapper;
import com.justgame.project.cloud.common.query.Query;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.justgame.project.service.art.entity.ArtPageGameMap;
import com.justgame.project.service.just.query.JustGameInfoQuery;
import com.justgame.project.service.just.entity.JustGameInfo;
import com.justgame.project.service.art.entity.ArtPageInfo;
import com.justgame.project.service.art.query.ArtPageInfoQuery;
import com.justgame.project.service.art.wrapper.ArtPageGameMapWrapper;

public class ArtPageGameMapQuery extends AbstractQueryWrapper<ArtPageGameMap, MPJLambdaWrapper<ArtPageGameMap>, ArtPageGameMapWrapper> {

    private ArtPageGameMapQuery() {
        super(new MPJLambdaWrapper<>(ArtPageGameMap.class,"art_page_game_map"));
    }

    public static ArtPageGameMapQuery builder(){
        return new ArtPageGameMapQuery();
    }

    public static class Select{

        private final List<Query> queries;

        protected Select(){
            queries = new ArrayList<>();
        }

        protected Select(List<Query> queries) {
            this.queries = queries;
        }

        public Query[] getQueriesArray() {
            return queries.toArray(new Query[0]);
        }

        public static SelectBuilder builder(){
            return new SelectBuilder();
        }

        public Query[] build(){
            return queries.toArray(new Query[0]);
        }

        public static class SelectBuilder extends BaseSelectBuilder {
            public SelectBuilder ArtPageGameMap(){
                return ArtPageGameMap(Column.all());
            }

            public SelectBuilder ArtPageGameMap(Column column){
                return add(Query.builder(ArtPageGameMap.class)
                            .selectColumns(column)
                            .build());
            }

            public SelectBuilder artPageInfo(){
                return artPageInfo(Column.all());
            }

            public SelectBuilder artPageInfo(Column column){
                return artPageInfo(column, null);
            }

            public SelectBuilder artPageInfo(Column column,ArtPageInfoQuery.Select selectQuery){
                return artPageInfo("artPageInfoWrapper", column, null);
            }

            public SelectBuilder artPageInfo(String mappingName,Column column,ArtPageInfoQuery.Select selectQuery){
                return add(Query.builder(ArtPageInfo.class)
                            .mapping(mappingName)
                            .leftOn((SFunction<ArtPageInfo,?>)ArtPageInfo::getId)
                            .rightOn((SFunction<ArtPageGameMap,?>)ArtPageGameMap::getPageId)
                            .selectColumns(column)
                            .join(Optional.ofNullable(selectQuery).map(ArtPageInfoQuery.Select::getQueriesArray).orElse(null))
                            .build());
            }

            public SelectBuilder justGameInfo(){
                return justGameInfo(Column.all());
            }

            public SelectBuilder justGameInfo(Column column){
                return justGameInfo(column, null);
            }

            public SelectBuilder justGameInfo(Column column,JustGameInfoQuery.Select selectQuery){
                return justGameInfo("justGameInfoWrapper", column, null);
            }

            public SelectBuilder justGameInfo(String mappingName,Column column,JustGameInfoQuery.Select selectQuery){
                return add(Query.builder(JustGameInfo.class)
                            .mapping(mappingName)
                            .leftOn((SFunction<JustGameInfo,?>)JustGameInfo::getId)
                            .rightOn((SFunction<ArtPageGameMap,?>)ArtPageGameMap::getGameInfoId)
                            .selectColumns(column)
                            .join(Optional.ofNullable(selectQuery).map(JustGameInfoQuery.Select::getQueriesArray).orElse(null))
                            .build());
            }

            public Select build(){
                return new Select(getQueries());
            }
        }

    }
}